<?php namespace Admin\Controller;
	
    use Common\Model\Brand;
	class BrandController extends CommonController{
	 private $db;

	public function __init(){
		$this->db=new Brand;
		parent::__init();
	}
	public function index(){
	$data=$this->db->orderBy('sort','DESC')->get();
	View::with('data',$data);
      View::make();
	}
		
	public function add(){
        if(IS_POST){
//      	var_dump($_POST);die;
		 $result=$this->db->store();
			if(!$result){
			View::error($this->db->getError());	
			}
         View::success('添加成功',U('index'));
        }
		View::make();
	}
	public function edit(){
		View::make();
	}
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$this->db->where('bid',$bid)->delete();
		View::success('删除成功',U('index'));
	}
		
		public function upload(){
			$file = Upload::path('Upload/Content/' . date('y/m'))->make();
		    if (empty($file)) {
		        $this->ajax(Upload::getError());
		    } else {
		        /** $file内部就是以下这个数组
		            $file = array(
		                0 => array(
		                'path' => 'Upload/Content/15/8/123981239172.jpg'    ,
		                'url' => 'http://localhost/cms_edu/Upload/Content/15/8/123981239172.jpg',
		                'image' => 1
		            ),
		        );**/
		        //上传成功，把上传好的信息返给js
		        $data = $file[0];
		        echo json_encode($data);exit;
//				View::ajax($data);die;
		    }
		}
		
	}
	
	
	?>